route.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { ApiPath } from "@/app/constant";
  2. import { NextRequest } from "next/server";
  3. import { handle as openaiHandler } from "../../openai";
  4. import { handle as azureHandler } from "../../azure";
  5. import { handle as googleHandler } from "../../google";
  6. import { handle as anthropicHandler } from "../../anthropic";
  7. import { handle as baiduHandler } from "../../baidu";
  8. import { handle as bytedanceHandler } from "../../bytedance";
  9. import { handle as alibabaHandler } from "../../alibaba";
  10. import { handle as moonshotHandler } from "../../moonshot";
  11. import { handle as stabilityHandler } from "../../stability";
  12. import { handle as iflytekHandler } from "../../iflytek";
  13. import { handle as proxyHandler } from "../../proxy";
  14. async function handle(
  15. req: NextRequest,
  16. { params }: { params: { provider: string; path: string[] } },
  17. ) {
  18. const apiPath = `/api/${params.provider}`;
  19. console.log(`[${params.provider} Route] params `, params);
  20. switch (apiPath) {
  21. case ApiPath.Azure:
  22. return azureHandler(req, { params });
  23. case ApiPath.Google:
  24. return googleHandler(req, { params });
  25. case ApiPath.Anthropic:
  26. return anthropicHandler(req, { params });
  27. case ApiPath.Baidu:
  28. return baiduHandler(req, { params });
  29. case ApiPath.ByteDance:
  30. return bytedanceHandler(req, { params });
  31. case ApiPath.Alibaba:
  32. return alibabaHandler(req, { params });
  33. // case ApiPath.Tencent: using "/api/tencent"
  34. case ApiPath.Moonshot:
  35. return moonshotHandler(req, { params });
  36. case ApiPath.Stability:
  37. return stabilityHandler(req, { params });
  38. case ApiPath.Iflytek:
  39. return iflytekHandler(req, { params });
  40. case ApiPath.OpenAI:
  41. return openaiHandler(req, { params });
  42. default:
  43. return proxyHandler(req, { params });
  44. }
  45. }
  46. export const GET = handle;
  47. export const POST = handle;
  48. export const runtime = "edge";
  49. export const preferredRegion = [
  50. "arn1",
  51. "bom1",
  52. "cdg1",
  53. "cle1",
  54. "cpt1",
  55. "dub1",
  56. "fra1",
  57. "gru1",
  58. "hnd1",
  59. "iad1",
  60. "icn1",
  61. "kix1",
  62. "lhr1",
  63. "pdx1",
  64. "sfo1",
  65. "sin1",
  66. "syd1",
  67. ];